package com.lzj.jiangxindaojia;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.google.gson.Gson;
import com.ifaa.sdk.api.AuthenticatorManager;
import com.ifaa.sdk.auth.AuthenticatorCallback;
import com.ifaa.sdk.auth.Constants;
import com.ifaa.sdk.auth.IAuthenticator;
import com.ifaa.sdk.auth.message.AuthenticatorMessage;
import com.ifaa.sdk.auth.message.AuthenticatorResponse;
import com.lzj.jiangxindaojia.bean.FingerLogin;
import com.lzj.jiangxindaojia.bean.FingerRegistInit;
import com.lzj.jiangxindaojia.bean.PhoneInfo;
import com.lzj.jiangxindaojia.bean.ResultCode;
import com.lzj.jiangxindaojia.bean.WxOrder;
import com.lzj.jiangxindaojia.http.HttpAction;
import com.lzj.jiangxindaojia.http.HttpCallBack;
import com.lzj.jiangxindaojia.http.HttpConstans;
import com.lzj.jiangxindaojia.http.HttpUtil;
import com.lzj.jiangxindaojia.utils.GsonUtil;
import com.lzj.jiangxindaojia.utils.LogUtils;
import com.lzj.jiangxindaojia.utils.MD5;
import com.lzj.jiangxindaojia.utils.PasswordInputView;
import com.lzj.jiangxindaojia.utils.SharePreferenceUtil;
import com.lzj.jiangxindaojia.utils.Utils;
import com.lzj.jiangxindaojia.view.login.PwdLoginActivity;
import com.lzj.jiangxindaojia.view.login.SettingZwLoginActivity;
import com.lzj.jiangxindaojia.view.login.ali.FingerPrintAuthActivity;
import com.lzj.jiangxindaojia.view.login.ali.FingerPrintToast;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import static com.lzj.jiangxindaojia.R.mipmap.back;

public class MainActivity1 extends AppCompatActivity implements HttpCallBack, View.OnClickListener, PasswordInputView.OnFinishListener {
    private TextView tv_tile;
    private ImageView iv_left,iv_right;
    private LinearLayout ll_left,ll_right;
    private String url = " ";
    public static WebView webView;
    private String token = "";
    private String open_info = "";
    private String user_id = "";
    private String open_userid = "";
    private String open_Id = "";
    private String paytoken = "", app_id, order_number, pay_type, order_amount, actual_amount, is_integral, integral_amount, coupons_id, coupons_amount;
    String city;
    private AMapLocationClient locationClient = null;
    private AMapLocationClientOption locationOption = null;
    String info;
    public static IAuthenticator authenticator;
    private HttpCallBack httpcallback;

    @TargetApi(Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.tv_tile = ((TextView) findViewById(R.id.tv_tile));
        this.iv_left = ((ImageView) findViewById(R.id.iv_left));
        this.iv_right = ((ImageView) findViewById(R.id.iv_right));
        this.ll_left = ((LinearLayout) findViewById(R.id.ll_left));
        this.ll_right = ((LinearLayout) findViewById(R.id.ll_right));
        this.tv_tile.setText("");
        iv_left.setImageResource(back);
        iv_right.setImageResource(R.mipmap.index);
//      this.ll_left.setVisibility(View.VISIBLE);
        ll_left.setOnClickListener(this);
        iv_right.setOnClickListener(this);
        iv_right.setVisibility(View.GONE);
        ll_right.setVisibility(View.GONE);

        webView = (WebView) findViewById(R.id.webview);
        token = SharePreferenceUtil.getData(this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.TOKEN);
        open_info = SharePreferenceUtil.getData(this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.OPEN_INFO);
        open_userid = SharePreferenceUtil.getData(this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.OPEN_USERID);
        open_Id = SharePreferenceUtil.getData(this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.OPEN_ID);
        user_id = SharePreferenceUtil.getData(this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.USER_ID);
//        open_info = Base64Utils.getBase64(open_info);
        httpcallback = this;

        authenticator = AuthenticatorManager.create(this, authType, "JXDJ");
//        if (ContextCompat.checkSelfPermission(MainActivity1.this,
//                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//            ActivityCompat.requestPermissions(MainActivity1.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
//        } else {
//            initLocation();
//            paramMap = new HashMap();
//            paramMap.put("openid", open_Id);
//            paramMap.put("type", "a");
//            paramMap.put("channel_number", "jd20160927009141");
//            paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
//            HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.MAIN_INDEX, paramMap, this, this, HttpAction.MAIN_INDEX);
//        }
        Intent intent = getIntent();  //Activity2
        String url = intent.getStringExtra("url");
        showWebView(url);
    }

    private boolean cityflag = true;

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case 1:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    cityflag = true;
                    initLocation();
                } else {
                    Toast.makeText(this, "你拒绝了这个权限", Toast.LENGTH_SHORT).show();
                    cityflag = false;
                }
                paramMap = new HashMap();
                paramMap.put("openid", open_Id);
                paramMap.put("type", "a");
                paramMap.put("channel_number", HttpConstans.qdnumber);
                paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.MAIN_INDEX, paramMap, this, this, HttpAction.MAIN_INDEX);
                break;
            default:
        }

    }

    /**
     * 检测是否支持IFAA
     */
    private int authType = Constants.TYPE_FINGERPRINT;

    private String isSupport() {
        String f = "0";
        boolean flag = AuthenticatorManager.isSupportIFAA(this, authType);

        if (flag) {
            f = "0";
        } else {
            f = "1";
        }
        return f;
    }

    private static final int MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1;
    private String server_response;
    private String mCurrentUrl, recharge_amount, hongbao_type, hongbao_count, total_amount, content, product_type, hongbao_style, order_env_type, created_by_nickname, created_by_headimgurl, open_userid_hb, recharge_type, recharge_phone, recharge_highest_amount, qd_user_id, recharge_goods_id;
    private Map<String, String> titles = new HashMap<String, String>();
    String fingeretype = "", deletefingeretype = "";
    Intent intent;
    Bundle bundle;

    private void showWebView(String web_url) {
        this.webView.getSettings().setAppCacheEnabled(true);
        this.webView.getSettings().setJavaScriptEnabled(true);
        this.webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

        this.webView.addJavascriptInterface(new Contact() {
            @JavascriptInterface
            public String getPhoneInfo() {
                PhoneInfo phoneInfo = new PhoneInfo();
                String phoneinfo;
                if ("0".equals(isSupport())) {
                    /**
                     * 获得授权数据
                     */
                    info = AuthenticatorManager.getAuthData(MainActivity1.this, SharePreferenceUtil.getData(MainActivity1.this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.USER_ID));
                    secData = info;
                    SharePreferenceUtil.keepDate(MainActivity1.this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.SEC_DATA, secData);
                    LogUtils.log("secdata  " + secData);
                    phoneInfo.setIssupport(isSupport());
                    phoneInfo.setSecdata(info);
                    phoneInfo.setAppid(HttpConstans.appid);
                } else {
                    phoneInfo.setIssupport(isSupport());
                    phoneInfo.setSecdata("");
                    phoneInfo.setAppid("");
                }
                return new Gson().toJson(phoneInfo);
            }

            @JavascriptInterface
            public void openFinger(final String content) {
                LogUtils.log("openFinger");
                fingeretype = "openFinger";
                requestOpenfinger(content);
            }

            @JavascriptInterface
            public void finishFinger(String content) {

                SettingZwLoginActivity.FingerprintBroadcastUtil.sendIdentifyStatusChangeMessage(MainActivity1.this, 0);

                MainActivity1.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        if ("openFinger".equals(fingeretype)) {
                            //调用js中的函数
                            webView.loadUrl("javascript: gobackApp()");
                        } else if ("openFingerPay".equals(fingeretype)) {
                            //调用js中的函数
                            webView.loadUrl("javascript: goApporder()");
                        }

                    }
                });
            }

            @JavascriptInterface
            public void openFingerPay(String token, final String content) {
                LogUtils.log("openFingerPay content  " + content);
                fingeretype = "openFingerPay";
                paytoken = token;
                try {
                    JSONObject jsonObject = new JSONObject(content);
                    app_id = jsonObject.getString("app_id");
                    order_number = jsonObject.getString("order_number");
                    pay_type = jsonObject.getString("pay_type");
                    order_amount = jsonObject.getString("order_amount");
                    actual_amount = jsonObject.getString("actual_amount");
                    is_integral = jsonObject.getString("is_integral");
                    integral_amount = jsonObject.getString("integral_amount");
                    coupons_id = jsonObject.getString("coupons_id");
                    coupons_amount = jsonObject.getString("coupons_amount");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                requestOpenfinger(content);
            }

            @JavascriptInterface
            public void hongbaoPay(String token, String param) {
                LogUtils.log("hongbaoPay content  " + param);
                fingeretype = "openFingerHongbaoPay";
                paytoken = token;
                try {
                    JSONObject jsonObject = new JSONObject(param);
                    recharge_amount = jsonObject.getString("recharge_amount");
                    order_number = jsonObject.getString("order_number");
                    hongbao_type = jsonObject.getString("hongbao_type");
                    hongbao_count = jsonObject.getString("hongbao_count");
                    total_amount = jsonObject.getString("total_amount");
                    content = jsonObject.getString("content");
                    product_type = jsonObject.getString("product_type");
                    open_userid_hb = jsonObject.getString("open_userid");
                    hongbao_style = jsonObject.getString("hongbao_style");
                    recharge_type = jsonObject.getString("recharge_type");
                    order_env_type = jsonObject.getString("order_env_type");
                    created_by_nickname = jsonObject.getString("created_by_nickname");
                    created_by_headimgurl = jsonObject.getString("created_by_headimgurl");
                } catch (Exception e) {
                    e.printStackTrace();
                }


                requestOpenfinger(content);
            }

            @JavascriptInterface
            public void giftPay(String token, String content) {
                LogUtils.log("giftPay content  " + content);
                fingeretype = "openFingerGiftPay";
                paytoken = token;
                try {
                    JSONObject jsonObject = new JSONObject(content);
                    recharge_phone = jsonObject.getString("recharge_phone");
                    order_number = jsonObject.getString("order_number");
                    recharge_amount = jsonObject.getString("recharge_amount");
                    recharge_highest_amount = jsonObject.getString("recharge_highest_amount");
                    order_env_type = jsonObject.getString("order_env_type");
                    qd_user_id = jsonObject.getString("qd_user_id");
                    product_type = jsonObject.getString("product_type");
                    recharge_type = jsonObject.getString("recharge_type");
                    recharge_goods_id = jsonObject.getString("recharge_goods_id");

                } catch (Exception e) {
                    e.printStackTrace();
                }

                requestOpenfinger(content);
            }

            @JavascriptInterface
            public void share(String content) {
                LogUtils.log("content " + content);

                if (!Utils.isWeixinAvilible(MainActivity1.this)) {
                    Toast.makeText(MainActivity1.this, "您还未安装微信客户端",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    JSONObject jsonObject = new JSONObject(content);
                    String title = jsonObject.getString("title");
                    String description = jsonObject.getString("description");
                    String img = jsonObject.getString("img");
                    String shareUrl = jsonObject.getString("url");

                    intent = new Intent(MainActivity1.this, ShareActivity.class);
                    bundle = new Bundle();
                    bundle.putString("html_url", shareUrl);
                    bundle.putString("title", title);
                    bundle.putString("content", description);
                    bundle.putString("img", img);
                    intent.putExtras(bundle);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @JavascriptInterface
            public void closePayfinger(String deletetoken) {
                deletefingeretype = "paydel";
                deleteFinger(deletetoken);
            }

            @JavascriptInterface
            public void wechatPay(String ordernum, String info) {
                LogUtils.log("ordernum " + ordernum);
                LogUtils.log("info " + info);
                if (!Utils.isWeixinAvilible(MainActivity1.this)) {
                    Toast.makeText(MainActivity1.this, "您还未安装微信客户端",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    JSONObject jsonObject = new JSONObject(info);
                    String noncestr = jsonObject.getString("noncestr");
                    String appid = jsonObject.getString("appid");
                    String sign = jsonObject.getString("sign");
                    String partnerid = jsonObject.getString("partnerid");
                    String prepayid = jsonObject.getString("prepayid");
                    String timestamp = jsonObject.getString("timestamp");
//                    String packagevalue = jsonObject.getString("package");

                    //解析对面的传过来的订单信息，放WxOrder里面
                    //随机字符串
//                    String nonce_str = ResourceUtil.createRandomString(32);
                    WxOrder wxOrder = new WxOrder();
                    wxOrder.setAppid(appid);
                    wxOrder.setPackagevalue("Sign=WXPay");
                    wxOrder.setPartnerid(partnerid);
                    wxOrder.setPrepayid(prepayid);
                    wxOrder.setSign(sign);
                    wxOrder.setTimestamp(timestamp);
                    wxOrder.setNoncestr(noncestr);
                    weChatPayOrder(wxOrder);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }


            @JavascriptInterface
            public void openFingerLogin(String password) {
                LogUtils.log("openFingerLogin");
                fingeretype = "openFingerlogin";
                requestOpenfinger(password);
            }

            /**
             * 关闭指纹登录
             */
            @JavascriptInterface
            public void closefinger(String deletetoken) {
                deletefingeretype = "logindel";
                deleteFinger(deletetoken);
            }

            @JavascriptInterface
            public void signOut() {
                LogUtils.log("signOut");
                finish();
                Utils.goNextActivity(MainActivity1.this, PwdLoginActivity.class);
            }

        }, "android");
//        webView.setWebViewClient(new WebViewClient(){
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                webView.loadUrl(url);
//                return true;
//            }
//
//            @Override
//            public void onPageStarted(WebView view, String url, Bitmap favicon) {
//                super.onPageStarted(view, url, favicon);
//                LogUtils.log("start:"+url);
//                mCurrentUrl = url;
//            }
//
//            @Override
//            public void onPageFinished(WebView view, String url) {
//                super.onPageFinished(view, url);
//                LogUtils.log("finish:"+url);
//                String title = titles.get(url);
//                if (!TextUtils.isEmpty(title)){
//                    tv_tile.setText(title);
//                }
//
//            }
//        });
//
//        webView.setWebChromeClient(new WebChromeClient(){
//            @Override
//            public void onReceivedTitle(WebView view, String title) {
//                super.onReceivedTitle(view, title);
//                LogUtils.log("title:"+title);
//                if (TextUtils.isEmpty(title)){
//                    title = "";
//                }
//                titles.put(mCurrentUrl,title);
//            }
//
//            @Override
//            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
//                return super.onJsAlert(view, url, message, result);
//            }
//        });



        webView.setWebViewClient(new WebViewClient() {
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                view.loadUrl(url);
//                return true;
//            }
            //是否在webview内加载页面
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view.loadUrl(request.getUrl().toString());
                } else {
                    view.loadUrl(request.toString());
                }
                return false;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                LogUtils.log("shouldOverrideUrlLoading "+ url);
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                if (!isLoadUrl) {
                    isLoadUrl = true;
                    view.loadUrl(url);
                }
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                Toast.makeText(MainActivity1.this, "网页加载完毕", Toast.LENGTH_SHORT).show();
                LogUtils.log( "onPageFinished 网页加载完毕"+url);
                super.onPageFinished(view, url);
            }


        });
        this.webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                LogUtils.log("222");
                if (title != null) {
                    if (title.equals("匠心到家") || title.equals("发现") || title.equals("个人中心")) {
                        ll_left.setVisibility(View.GONE);
                    } else {
                        ll_left.setVisibility(View.VISIBLE);
                    }
                    tv_tile.setText(title);
                }
            }

        });

        this.webView.loadUrl(web_url);
    }



    private boolean isLoadUrl = false;

    private AuthenticatorCallback regCallback = new AuthenticatorCallback() {
        @Override
        public void onStatus(int status) {
            SettingZwLoginActivity.FingerprintBroadcastUtil.sendIdentifyStatusChangeMessage(MainActivity1.this, status);
        }

        @Override
        public void onResult(final AuthenticatorResponse response) {
            final String data = response.getData();
            LogUtils.log("reg respone info:" + data);
            if (response.getResult() == AuthenticatorResponse.RESULT_SUCCESS) {
                paramMap = new HashMap();
                if ("openFinger".equals(fingeretype)) {
                    paramMap.put("type", "2");
                    paramMap.put("token_type", "pay_token");
                    paramMap.put("app_id", HttpConstans.appid);
                    paramMap.put("channel_number", HttpConstans.qdnumber);
                    paramMap.put("open_info", open_info);
                    paramMap.put("token", token);
                    paramMap.put("user_id", user_id);
                    paramMap.put("ifaf_message", data);
                    paramMap.put("sec_data", secData);
                    paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                    HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_LOGIN_REGIST, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
                } else if ("openFingerPay".equals(fingeretype)) {
                    paramMap.put("type", "4");
                    paramMap.put("verify_type", "pay_verify");
                    paramMap.put("app_id", app_id);
                    paramMap.put("source", HttpConstans.qdnumber);
                    paramMap.put("user_id", user_id);
                    paramMap.put("ifaf_message", data);
                    paramMap.put("sec_data", secData);
                    paramMap.put("subAction", "verify");

                    paramMap.put("order_number", order_number);
                    paramMap.put("pay_type", pay_type);
                    paramMap.put("order_amount", order_amount);
                    paramMap.put("actual_amount", actual_amount);
                    paramMap.put("is_integral", is_integral);
                    paramMap.put("integral_amount", integral_amount);
                    if (!"".equals(coupons_id)) {
                        paramMap.put("coupons_id", coupons_id);
                    }
                    if (!"".equals(coupons_amount)) {
                        paramMap.put("coupons_amount", coupons_amount);
                    }
                    paramMap.put("payment", "JXDJ_PAY");
                    paramMap.put("pay_mark", "1");
                    paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                    HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_PAY, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
                } else if ("openFingerHongbaoPay".equals(fingeretype)) {
                    paramMap.put("type", "4");
                    paramMap.put("verify_type", "pay_verify");
//                    paramMap.put("app_id", app_id);
//                    paramMap.put("source", "jd20160927009141");
                    paramMap.put("user_id", user_id);
                    paramMap.put("ifaf_message", data);
                    paramMap.put("sec_data", secData);
                    paramMap.put("subAction", "verify");

                    paramMap.put("order_number", order_number);
                    paramMap.put("product_type", product_type);
                    paramMap.put("open_userid", open_userid_hb);
                    paramMap.put("recharge_type", recharge_type);
                    paramMap.put("hongbao_type", hongbao_type);
                    paramMap.put("hongbao_style", hongbao_style);
                    paramMap.put("recharge_amount", recharge_amount);
                    paramMap.put("hongbao_count", hongbao_count);
                    paramMap.put("content", content);
                    paramMap.put("created_by_nickname", created_by_nickname);
                    paramMap.put("created_by_headimgurl", created_by_headimgurl);
                    paramMap.put("pay_mark", "1");
                    paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                    HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_RECHANGE, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
                } else if ("openFingerGiftPay".equals(fingeretype)) {
                    paramMap.put("type", "4");
                    paramMap.put("verify_type", "pay_verify");
//                    paramMap.put("app_id", app_id);
//                    paramMap.put("source", "jd20160927009141");
                    paramMap.put("user_id", user_id);
                    paramMap.put("ifaf_message", data);
                    paramMap.put("sec_data", secData);
                    paramMap.put("subAction", "verify");

                    paramMap.put("order_number", order_number);
                    paramMap.put("product_type", product_type);
                    paramMap.put("qd_user_id", qd_user_id);
                    paramMap.put("recharge_type", recharge_type);
                    paramMap.put("recharge_phone", recharge_phone);
                    paramMap.put("recharge_amount", recharge_amount);
                    paramMap.put("recharge_highest_amount", recharge_highest_amount);
                    paramMap.put("recharge_goods_id", recharge_goods_id);
                    paramMap.put("pay_mark", "1");
                    paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                    HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_RECHANGE, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
                } else if ("openFingerlogin".equals(fingeretype)) {
                    paramMap.put("type", "2");
                    paramMap.put("token_type", "login_token");
                    paramMap.put("app_id", HttpConstans.appid);
                    paramMap.put("channel_number", HttpConstans.qdnumber);
                    paramMap.put("open_info", open_info);
                    paramMap.put("token", token);
                    paramMap.put("user_id", user_id);
                    paramMap.put("ifaf_message", data);
                    paramMap.put("sec_data", secData);
                    paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                    HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_LOGIN_REGIST, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
                }


            } else {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        new FingerPrintToast(MainActivity1.this, FingerPrintToast.ST_REGFAIL).show("指纹不匹配");
                        showpassword(MainActivity1.this);
//                        new FingerPrintToast(MainActivity.this, FingerPrintToast.ST_REGFAIL).show("reg fail:" + response.getResult());
                        SettingZwLoginActivity.FingerprintBroadcastUtil.sendIdentifyStatusChangeMessage(MainActivity1.this, 0);
                    }
                });
            }
        }
    };

    public void startFPActivity(boolean isAuthenticate) {
        Intent intent = new Intent();
//        if (isAuthenticate) {
//            intent.putExtra(AuthenticatorMessage.KEY_OPERATIONT_TYPE,
//                    AuthenticatorMessage.MSG_AUTHENTICATOR_REQUEST);
//        }
        intent.setClass(this, FingerPrintAuthActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.startActivity(intent);
    }
    //手机返回键 返回功能


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_left:
                if(webView.canGoBack()){
                    webView.goBack(); // goBack()表示返回WebV
                }else {
                    finish();
                }
                break;
            case R.id.iv_right:
                MainActivity.goIndex();
                finish();
                break;
        }
    }

    /**
     * 监听Back键按下事件,方法2:
     * 注意:
     * 返回值表示:是否能完全处理该事件
     * 在此处返回false,所以会继续传播该事件.
     * 在具体项目中此处的返回值视情况而定.
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
                    if(webView.canGoBack()){
                        webView.goBack(); // goBack()表示返回WebV
                    }else {
                        finish();
                    }
                    //titles.remove(titles.size() - 1);
                    //webview_title.setText(titles.get(titles.size() - 1));
                    return true;
                } else {
                    finish();
                }
            }
            return false;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    /**
     * 密码输入框输入完成
     */
    @Override
    public void setOnPasswordFinished() {
        LogUtils.log("setOnPasswordFinished");
        if (passwordView.getOriginText().length() == passwordView.getMaxPasswordLength()) {
            Toast.makeText(this, "密码为" + passwordView.getOriginText(), Toast.LENGTH_LONG).show();
            paramMap = new HashMap();
            if ("openFingerPay".equals(fingeretype)) {
//                paramMap.put("type", "4");
//                paramMap.put("verify_type", "pay_verify");
                paramMap.put("app_id", app_id);
                paramMap.put("source", HttpConstans.qdnumber);
                paramMap.put("user_id", user_id);
//                paramMap.put("ifaf_message", data);
//                paramMap.put("sec_data", secData);
//                paramMap.put("subAction", "verify");

                paramMap.put("order_number", order_number);
                paramMap.put("pay_type", pay_type);
                paramMap.put("order_amount", order_amount);
                paramMap.put("actual_amount", actual_amount);
                paramMap.put("is_integral", is_integral);
                paramMap.put("integral_amount", integral_amount);
                if (!"".equals(coupons_id)) {
                    paramMap.put("coupons_id", coupons_id);
                }
                if (!"".equals(coupons_amount)) {
                    paramMap.put("coupons_amount", coupons_amount);
                }
                paramMap.put("payment", "JXDJ_PAY");

                paramMap.put("pay_mark", "2");
                paramMap.put("password",  MD5.md5(passwordView.getOriginText()));

                paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_PAY, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
            } else if ("openFingerHongbaoPay".equals(fingeretype)) {
//                paramMap.put("type", "4");
//                paramMap.put("verify_type", "pay_verify");
//                    paramMap.put("app_id", app_id);
//                    paramMap.put("source", HttpConstans.qdnumber);
                paramMap.put("user_id", user_id);
//                paramMap.put("ifaf_message", data);
//                paramMap.put("sec_data", secData);
//                paramMap.put("subAction", "verify");

                paramMap.put("order_number", order_number);
                paramMap.put("product_type", product_type);
                paramMap.put("open_userid", open_userid_hb);
                paramMap.put("recharge_type", recharge_type);
                paramMap.put("hongbao_type", hongbao_type);
                paramMap.put("hongbao_style", hongbao_style);
                paramMap.put("recharge_amount", recharge_amount);
                paramMap.put("hongbao_count", hongbao_count);
                paramMap.put("content", content);
                paramMap.put("created_by_nickname", created_by_nickname);
                paramMap.put("created_by_headimgurl", created_by_headimgurl);

                paramMap.put("pay_mark", "2");
                paramMap.put("password", MD5.md5(passwordView.getOriginText()));

                paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_RECHANGE, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
            } else if ("openFingerGiftPay".equals(fingeretype)) {
//                paramMap.put("type", "4");
//                paramMap.put("verify_type", "pay_verify");
//                    paramMap.put("app_id", app_id);
//                    paramMap.put("source", HttpConstans.qdnumber);
                paramMap.put("user_id", user_id);
//                paramMap.put("ifaf_message", data);
//                paramMap.put("sec_data", secData);
//                paramMap.put("subAction", "verify");

                paramMap.put("order_number", order_number);
                paramMap.put("product_type", product_type);
                paramMap.put("qd_user_id", qd_user_id);
                paramMap.put("recharge_type", recharge_type);
                paramMap.put("recharge_phone", recharge_phone);
                paramMap.put("recharge_amount", recharge_amount);
                paramMap.put("recharge_highest_amount", recharge_highest_amount);
                paramMap.put("recharge_goods_id", recharge_goods_id);

                paramMap.put("pay_mark", "2");
                paramMap.put("password",  MD5.md5(passwordView.getOriginText()));

                paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
                HttpUtil.getInstance(MainActivity1.this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_RECHANGE, paramMap, MainActivity1.this, httpcallback, HttpAction.FINGER_LOGIN_REGIST);
            }
        }
    }

    private AlertDialog dialog;
    private PasswordInputView passwordView;
    TextView money;
    public void showpassword(Context context) {
        dialog = new AlertDialog.Builder(context, R.style.AppBaseTheme1).create();
        dialog.show();
        //按对话框以外的地方不起作用。按返回键还起作用
        //setCancelable(false);调用这个方法时，按对话框以外的地方不起作用。按返回键也不起作用
        dialog.setCanceledOnTouchOutside(false);
        Window localWindow = dialog.getWindow();
        localWindow.clearFlags(131072);
        localWindow.setContentView(R.layout.dialog_password);
        localWindow.setGravity(17);
        localWindow.setLayout(-1, -2);
        LinearLayout localLinearLayout = (LinearLayout) localWindow.findViewById(R.id.ll_dialog);
        int j;
        int i;
        j = Color.parseColor("#FFFFFF");
        i = Color.parseColor("#FFFFFF");
        GradientDrawable localGradientDrawable = new GradientDrawable();
        localGradientDrawable.setColor(i);
        localGradientDrawable.setCornerRadius(10);
        localGradientDrawable.setStroke(5, j);
        localLinearLayout.setBackgroundDrawable(localGradientDrawable);
        ImageView close = ((ImageView) localWindow.findViewById(R.id.close));
        money = ((TextView) localWindow.findViewById(R.id.money));
        money.setText("￥"+actual_amount);
        passwordView = ((PasswordInputView) localWindow.findViewById(R.id.password_view));
        passwordView.setOnFinishListener(this);
        close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                dialog.dismiss();
            }
        });
    }


    private interface Contact {
        public abstract String getPhoneInfo();

        public abstract void openFinger(String content);

        public abstract void finishFinger(String content);

        public abstract void openFingerPay(String token, String content);

        public abstract void hongbaoPay(String token, String content);

        public abstract void giftPay(String token, String content);

        public abstract void share(String content);

        public abstract void closePayfinger(String deletetoken);

        public abstract void wechatPay(String ordernum, String info);

        public abstract void openFingerLogin(String password);

        public abstract void closefinger(String deletetoken);

        public abstract void signOut();

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        destroyLocation();
        //清空所有Cookie
        CookieSyncManager.createInstance(this);  //Create a singleton CookieSyncManager within a context
        CookieManager cookieManager = CookieManager.getInstance(); // the singleton CookieManager instance
        cookieManager.removeAllCookie();// Removes all cookies.
        CookieSyncManager.getInstance().sync(); // forces sync manager to sync now

        webView.setWebChromeClient(null);
        webView.setWebViewClient(null);
        webView.getSettings().setJavaScriptEnabled(false);
        webView.clearCache(true);
    }


    public void deleteFinger(String deletetoken) {

//        String deletepaytoken = SharePreferenceUtil.getData(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.REGIST_PAYTOKEN);
//        String deletelogintoken = SharePreferenceUtil.getData(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.REGIST_LOGINTOKEN);
        paramMap = new HashMap();
        paramMap.put("type", "5");
        if ("logindel".equals(deletefingeretype)) {
            paramMap.put("delete_type", "login_del");
        } else if ("paydel".equals(deletefingeretype)) {
            paramMap.put("delete_type", "pay_del");
        }
        paramMap.put("app_id", HttpConstans.appid);
        paramMap.put("channel_number", HttpConstans.qdnumber);
        paramMap.put("user_id", user_id);
        paramMap.put("open_info", open_info);
        paramMap.put("token", token);
        paramMap.put("delete_token", deletetoken);
        paramMap.put("ifaa_version", "2.0");
        paramMap.put("sec_data", SharePreferenceUtil.getData(MainActivity1.this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.SEC_DATA));
        paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
        HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_DELETE, paramMap, this, this, HttpAction.FINGER_DELETE);
    }

    private String secData = "";

    public enum Process {
        REG_GETREQ, REG_SENDRESP, AUTH_GETREQ, AUTH_SENDRESP, MUITLFINGERS_AUTH_SENDRESP, DEREG_GETREQ
    }

    private Process curProcess = Process.REG_GETREQ;
    private HashMap paramMap;

    public void requestOpenfinger(String password) {

        /**
         * 检测是否支持IFAA
         */
        if (!AuthenticatorManager.isSupportIFAA(this, authType)) {
            Toast.makeText(this, "This device not support IFAA", Toast.LENGTH_LONG).show();
            return;
        }
        authenticator = AuthenticatorManager.create(this, authType, "JXDJ");
        LogUtils.log("hasEnrolled:" + authenticator.hasEnrolled());
        if (!authenticator.hasEnrolled()) {//是否录过指纹
            authenticator.startSystemEnrollManger();//去系统设置页面录指纹
        }
        curProcess = Process.REG_GETREQ;
        /**
         * 获得授权数据
         */
        String info = AuthenticatorManager.getAuthData(this, SharePreferenceUtil.getData(this, SharePreferenceUtil.USERINFO, SharePreferenceUtil.USER_ID));
//                    IFAAFingerprintOpenAPI.getInstance().getRegRequestAsyn(info, callback);
        secData = info;
        SharePreferenceUtil.keepDate(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.SEC_DATA, secData);
        LogUtils.log("reg info:" + info);

        paramMap = new HashMap();
        if ("openFinger".equals(fingeretype)) {//指纹支付
            paramMap.put("type", "1");
            paramMap.put("auth_type", "1");
            paramMap.put("app_id", HttpConstans.appid);
            paramMap.put("channel_number", HttpConstans.qdnumber);
            paramMap.put("open_info", open_info);
            paramMap.put("token", token);
            paramMap.put("sec_data", secData);
            paramMap.put("user_id", user_id);
            paramMap.put("password", password);
            LogUtils.log("sin " + MD5.createSignString(paramMap));
            paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
            HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_OPEN_PAY_INIT, paramMap, this, this, HttpAction.FINGER_OPEN_PAY_INIT);
        } else if ("openFingerPay".equals(fingeretype)) {
            String token = SharePreferenceUtil.getData(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.REGIST_PAYTOKEN);
            paramMap.put("type", "3");
            paramMap.put("app_id", HttpConstans.appid);
            paramMap.put("channel_number", HttpConstans.qdnumber);
            paramMap.put("verify_token", paytoken);
            paramMap.put("sec_data", secData);
            paramMap.put("ifaa_version", "2.0");
            LogUtils.log("sin " + MD5.createSignString(paramMap));
            paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
            HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_LOGIN_REGIST, paramMap, this, this, HttpAction.FINGER_OPEN_PAY_INIT);
        } else if ("openFingerHongbaoPay".equals(fingeretype)) {
            String token = SharePreferenceUtil.getData(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.REGIST_PAYTOKEN);
            paramMap.put("type", "3");
            paramMap.put("app_id", HttpConstans.appid);
            paramMap.put("channel_number", HttpConstans.qdnumber);
            paramMap.put("verify_token", paytoken);
            paramMap.put("sec_data", secData);
            paramMap.put("ifaa_version", "2.0");
            LogUtils.log("sin " + MD5.createSignString(paramMap));
            paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
            HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_LOGIN_REGIST, paramMap, this, this, HttpAction.FINGER_OPEN_PAY_INIT);
        } else if ("openFingerGiftPay".equals(fingeretype)) {
            String token = SharePreferenceUtil.getData(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.REGIST_PAYTOKEN);
            paramMap.put("type", "3");
            paramMap.put("app_id", HttpConstans.appid);
            paramMap.put("channel_number", HttpConstans.qdnumber);
            paramMap.put("verify_token", paytoken);
            paramMap.put("sec_data", secData);
            paramMap.put("ifaa_version", "2.0");
            LogUtils.log("sin " + MD5.createSignString(paramMap));
            paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
            HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_LOGIN_REGIST, paramMap, this, this, HttpAction.FINGER_OPEN_PAY_INIT);
        } else if ("openFingerlogin".equals(fingeretype)) {
            paramMap.put("type", "1");
            paramMap.put("auth_type", "1");
            paramMap.put("app_id", HttpConstans.appid);
            paramMap.put("channel_number", HttpConstans.qdnumber);
            paramMap.put("open_info", open_info);
            paramMap.put("token", token);
            paramMap.put("sec_data", secData);
            LogUtils.log("sin " + MD5.createSignString(paramMap));
            paramMap.put("sign", MD5.md5(MD5.createSignString(paramMap) + HttpConstans.KEY));
            HttpUtil.getInstance(this).postAsynHttp(HttpConstans.BASEURL + HttpConstans.FINGER_REGIST_INIT, paramMap, this, this, HttpAction.FINGER_OPEN_PAY_INIT);
        }
    }


    private FingerRegistInit fingerRegistInit;
    private FingerLogin fingerLogin;

    @Override
    public <T> void onSuccess(String result, String action) {
        switch (action) {
            case HttpAction.FINGER_OPEN_PAY_INIT:
                fingerRegistInit = GsonUtil.GsonToBean(result, FingerRegistInit.class);
                if (ResultCode.SUCCESS.equals(fingerRegistInit.getStatus())) {
                    startFPActivity(false);
                    if ("openFinger".equals(fingeretype)) {
                        AuthenticatorMessage requestMessage = new AuthenticatorMessage(AuthenticatorMessage.MSG_REGISTER_REQUEST, 2);
                        requestMessage.setData(fingerRegistInit.getData().getContent());
                        authenticator.process(requestMessage, regCallback);
                    } else if ("openFingerPay".equals(fingeretype)) {
                        AuthenticatorMessage requestMessage = new AuthenticatorMessage(AuthenticatorMessage.MSG_AUTHENTICATOR_REQUEST, 2);
                        requestMessage.setData(fingerRegistInit.getData().getContent());
                        authenticator.process(requestMessage, regCallback);
                    } else if ("openFingerlogin".equals(fingeretype)) {
                        AuthenticatorMessage requestMessage = new AuthenticatorMessage(AuthenticatorMessage.MSG_REGISTER_REQUEST, 2);
                        requestMessage.setData(fingerRegistInit.getData().getContent());
                        authenticator.process(requestMessage, regCallback);
                    } else if ("openFingerGiftPay".equals(fingeretype)) {
                        AuthenticatorMessage requestMessage = new AuthenticatorMessage(AuthenticatorMessage.MSG_AUTHENTICATOR_REQUEST, 2);
                        requestMessage.setData(fingerRegistInit.getData().getContent());
                        authenticator.process(requestMessage, regCallback);
                    } else if ("openFingerHongbaoPay".equals(fingeretype)) {
                        AuthenticatorMessage requestMessage = new AuthenticatorMessage(AuthenticatorMessage.MSG_AUTHENTICATOR_REQUEST, 2);
                        requestMessage.setData(fingerRegistInit.getData().getContent());
                        authenticator.process(requestMessage, regCallback);
                    }

                } else {
                    Utils.showToast(MainActivity1.this, fingerRegistInit.getMsg());
                }
                break;
            case HttpAction.FINGER_LOGIN_REGIST:
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("msg");
                    String data = jsonObject.getString("data");
                    LogUtils.log("token " + data);
                    if (ResultCode.SUCCESS.equals(status)) {
                        token = data;
                        SharePreferenceUtil.keepDate(this, SharePreferenceUtil.TOKENFILE, SharePreferenceUtil.REGIST_PAYTOKEN, token);
                        if ("openFinger".equals(fingeretype)) {
                            //调用js中的函数
                            webView.loadUrl("javascript:gobackApp()");
                        } else if ("openFingerPay".equals(fingeretype)) {
                            JSONObject jsonObject1 = new JSONObject(data);
//                            String location = jsonObject.getString("location");
//                            LogUtils.log("location "+location);
                           // http:\/\/kaifa.gomaster.cn\/rest\/notify\/zbt_return.php
                            Utils.goNextActivity(this,MainActivity1.class);

                            //调用js中的函数
                            webView.loadUrl("javascript:goApporder('" + data + "')");

                        } else if ("openFingerlogin".equals(fingeretype)) {
                            //调用js中的函数
                            webView.loadUrl("javascript:openFingerLogin()");
                        } else if ("openFingerGiftPay".equals(fingeretype)) {

                            //调用js中的函数
                            webView.loadUrl("javascript:giftBack('" + data + "')");
                        } else if ("openFingerHongbaoPay".equals(fingeretype)) {
                            //调用js中的函数
                            webView.loadUrl("javascript:hongbaoBack('" + data + "')");
                        }

                    } else {
                        Utils.showToast(this, msg);
                    }
                    /**
                     * 指纹页面消失
                     */
                    FingerprintBroadcastUtil.sendIdentifyStatusChangeMessage(MainActivity1.this, 0);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case HttpAction.FINGER_DELETE:
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("msg");
                    String data = jsonObject.getString("data");
                    if (ResultCode.SUCCESS.equals(status)) {
                        if ("logindel".equals(deletefingeretype)) {
                            //调用js中的函数  告诉H5解除成功
                            webView.loadUrl("javascript:closeLogin()");
                        } else if ("paydel".equals(deletefingeretype)) {
                            //调用js中的函数  告诉H5解除成功
                            webView.loadUrl("javascript:closePay()");
                        }
                    } else {
                        Utils.showToast(this, msg);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case HttpAction.MAIN_INDEX:
                LogUtils.log("cityflag  " + cityflag);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("msg");
                    String data = jsonObject.getString("data");
                    if (ResultCode.SUCCESS.equals(status)) {
                        url = data;
                        if (cityflag) {
                            startLocation();
                        } else {
                            url = url + "&city=中国";
                            LogUtils.log("url  " + url);
                            showWebView(url);
                        }

                    } else {
                        Utils.showToast(this, msg);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    private IWXAPI api;

    public void weChatPayOrder(WxOrder wxOrder) {
//        api = WXAPIFactory.createWXAPI(this, null);
//        api.registerApp(wxOrder.getAppid());
        final IWXAPI api = WXAPIFactory.createWXAPI(this, wxOrder.getAppid(), false);
        PayReq req = new PayReq();
        req.appId = wxOrder.getAppid();
        req.partnerId = wxOrder.getPartnerid();
        req.prepayId = wxOrder.getPrepayid();
        req.nonceStr = wxOrder.getNoncestr();
        req.timeStamp = wxOrder.getTimestamp();
        req.packageValue = wxOrder.getPackagevalue();
//        req.sign            = SignUtil.signByMD5("appid=" + wxOrder.getAppid() + "&noncestr=" + wxOrder.getNoncestr() + "&package=Sign=WXPay" +
//                "&partnerid=" + wxOrder.getPartnerid() + "&prepayid=" + wxOrder.getPrepayid()+ "×tamp=" + wxOrder.getTimestamp() + "&key=" + "kejiangzhongguo2017WEIJIANG1227A").toUpperCase(Locale.getDefault());

        req.sign = wxOrder.getSign();
//        req.extData			= "app data"; // optional
        api.sendReq(req);
    }

    /**
     * @author qiyi.wxc
     * @version $Id: FingerprintBroadcastUtil.java, v 0.1 2015年12月14日 下午7:44:55 qiyi.wxc Exp $
     */
    public static class FingerprintBroadcastUtil {

        //The is the broadcast for update UI status
        public final static String BROADCAST_FINGERPRINTSENSOR_STATUS_ACTION = "com.ifaa.sdk.authenticatorservice.broadcast.FINGERPRINTSENSOR_STATUS_ACTION";
        public final static String FINGERPRINTSENSOR_STATUS_VALUE = "com.ifaa.sdk.authenticatorservice.broadcast.FINGERPRINTSENSOR_STATUS_VALUE";

        //Send the UI Status of the FingerPrint Result and Change the UI
        public static void sendIdentifyStatusChangeMessage(Context context, int resultCode) {
            Intent broadcastIntent = new Intent(BROADCAST_FINGERPRINTSENSOR_STATUS_ACTION);
            broadcastIntent.putExtra(FINGERPRINTSENSOR_STATUS_VALUE, resultCode);
            broadcastIntent.setPackage(context.getPackageName());
            context.sendBroadcast(broadcastIntent);
        }

        public static IntentFilter getIdentifyChangeBroadcastFilter() {
            IntentFilter filter = new IntentFilter();
            filter.addAction(BROADCAST_FINGERPRINTSENSOR_STATUS_ACTION);
            return filter;
        }

    }

    /**
     * 初始化定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void initLocation() {
        //初始化client
        locationClient = new AMapLocationClient(this.getApplicationContext());
        locationOption = getDefaultOption();
        //设置定位参数
        locationClient.setLocationOption(locationOption);
        // 设置定位监听
        locationClient.setLocationListener(locationListener);
    }

    /**
     * 默认的定位参数
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private AMapLocationClientOption getDefaultOption() {
        AMapLocationClientOption mOption = new AMapLocationClientOption();
        mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选，设置定位模式，可选的模式有高精度、仅设备、仅网络。默认为高精度模式
        mOption.setGpsFirst(false);//可选，设置是否gps优先，只在高精度模式下有效。默认关闭
        mOption.setHttpTimeOut(30000);//可选，设置网络请求超时时间。默认为30秒。在仅设备模式下无效
        mOption.setInterval(2000);//可选，设置定位间隔。默认为2秒
        mOption.setNeedAddress(true);//可选，设置是否返回逆地理地址信息。默认是true
        mOption.setOnceLocation(true);//可选，设置是否单次定位。默认是false
        mOption.setOnceLocationLatest(true);//可选，设置是否等待wifi刷新，默认为false.如果设置为true,会自动变为单次定位，持续定位时不要使用
        AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选， 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
        mOption.setSensorEnable(false);//可选，设置是否使用传感器。默认是false
        mOption.setWifiScan(true); //可选，设置是否开启wifi扫描。默认为true，如果设置为false会同时停止主动刷新，停止以后完全依赖于系统刷新，定位位置可能存在误差
        mOption.setLocationCacheEnable(false); //可选，设置是否使用缓存定位，默认为true
        return mOption;
    }

    /**
     * 定位监听
     */
    AMapLocationListener locationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation location) {
            if (null != location) {
                stopLocation();
                LogUtils.log("定位成功" + "\n");
                LogUtils.log("城市  " + location.getCity());
                city = location.getCity();
//                            url = "http://test.zbtc.jiangxindaojia.com/#APP_index?token=" + token + "&channel_number=jd20160927009141&open_info=" + open_info + "&open_userid=" + open_userid + "&city=" + city;
                url = url + "&city=" + city;
                LogUtils.log("url  " + url);
                showWebView(url);
            } else {
                LogUtils.log("定位失败，loc is null");
            }
        }
    };


    /**
     * 销毁定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void destroyLocation() {
        if (null != locationClient) {
            /**
             * 如果AMapLocationClient是在当前Activity实例化的，
             * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
             */
            locationClient.onDestroy();
            locationClient = null;
            locationOption = null;
        }
    }

    /**
     * 停止定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void stopLocation() {
        // 停止定位
        locationClient.stopLocation();
    }

    /**
     * 开始定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void startLocation() {
        //根据控件的选择，重新设置定位参数
//        resetOption();
        // 设置定位参数
        locationClient.setLocationOption(locationOption);
        // 启动定位
        locationClient.startLocation();
    }


}
